| Conditions | 1 |
| Paths | 8 |
| Total Lines | 59 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | 'use strict' |
||
| 13 | export function devise (schema, opts) { |
||
| 14 | options = Object.assign({ |
||
| 15 | confirmable: { |
||
| 16 | tokenLifeSpan: 3 |
||
| 17 | }, |
||
| 18 | lockable: { |
||
| 19 | tokenLifeSpan: 3, |
||
| 20 | maximumAllowedFailedAttempts: 3 |
||
| 21 | }, |
||
| 22 | recoverable: { |
||
| 23 | tokenLifeSpan: 3 |
||
| 24 | }, |
||
| 25 | registerable: { |
||
| 26 | autoConfirm: false |
||
| 27 | } |
||
| 28 | }, opts) |
||
| 29 | |||
| 30 | /* |
||
| 31 | * format the string with the past values |
||
| 32 | */ |
||
| 33 | function stringFormat (key, values) { |
||
| 34 | let message = options[key] |
||
| 35 | if (values) { |
||
| 36 | Object.keys(values).forEach(param => { |
||
| 37 | message = message.replace(`{{${param}}}`, values[param]) |
||
| 38 | }) |
||
| 39 | } |
||
| 40 | return message |
||
| 41 | } |
||
| 42 | |||
| 43 | /* |
||
| 44 | * implementation of translator method |
||
| 45 | */ |
||
| 46 | function t (key, values) { |
||
| 47 | return options.i18n |
||
| 48 | ? options.i18n.t(key, values) |
||
| 49 | : stringFormat(key, values) |
||
| 50 | } |
||
| 51 | |||
| 52 | /* |
||
| 53 | * implementation of notification send |
||
| 54 | */ |
||
| 55 | function sendNotification (record, action, done) { |
||
| 56 | done() |
||
| 57 | } |
||
| 58 | |||
| 59 | schema.methods.sendNotification = schema.methods.send || sendNotification |
||
| 60 | |||
| 61 | // i18n adapter methodos |
||
| 62 | schema.methods.t = schema.methods.t || t |
||
| 63 | schema.statics.t = schema.statics.t || t |
||
| 64 | |||
| 65 | authenticable(schema, options) |
||
| 66 | confirmable(schema, options) |
||
| 67 | lockable(schema, options) |
||
| 68 | recoverable(schema, options) |
||
| 69 | registerable(schema, options) |
||
| 70 | trackable(schema) |
||
| 71 | } |
||
| 72 | |||
| 74 |